﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HomeAutomation
{
    class InsteonDevice : Device
    {
        private string _name;
        private string _id;

        public InsteonDevice(string name, string id)
        {
            _name = name;
            _id = id;
        }

        public string name()
        {
            return _name;
        }
        public string id()
        {
            return _id;
        }

        public override bool Equals(System.Object obj)
        {

            if (obj != null && obj is InsteonDevice)
            {
                InsteonDevice device = (InsteonDevice)obj;

                bool namesEqual = false;
                if (_name == null && device._name == null)
                {
                    namesEqual = true;
                }
                else if (_name != null)
                {
                    namesEqual = _name.Equals(device._name);
                }

                bool idsEqual = false;
                if (_id == null && device._id == null)
                {
                    idsEqual = true;
                }
                else if (_id != null)
                {
                    idsEqual = _id.Equals(device._id);
                }

                return namesEqual == true && idsEqual == true;

            }

            return false;

        }

        public override int GetHashCode()
        {
            int hash = 43;
            hash = hash * 41 + (_name != null ? _name.GetHashCode() : 0);
            hash = hash * 41 + (_id != null ? _id.GetHashCode() : 0);
            return hash;
        }

        public override string ToString()
        {
            return "InsteonDevice: " + _name + " " + _id;
        }
    }
}
